<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="umsroot.css">
<TITLE>
Less Common Topics
</TITLE>
</HEAD>
<BODY >
<A HREF="umsroot040.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot037.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc104">7.4</A>&nbsp;&nbsp;Less Common Topics</H2><UL>
<LI><A HREF="umsroot041.html#toc65">Modules Using Other Languages</A>
<LI><A HREF="umsroot041.html#toc66">Creating and Erasing Modules at Runtime</A>
<LI><A HREF="umsroot041.html#toc67">Initialization and Finalization</A>
<LI><A HREF="umsroot041.html#toc68">Locking Modules</A>
</UL>


<A NAME="toc65"></A>
<H3 CLASS="subsection"><A NAME="htoc105">7.4.1</A>&nbsp;&nbsp;Modules Using Other Languages</H3>

Modules created with the <A HREF="../bips/kernel/modules/module-1.html"><B>module/1</B></A><A NAME="@default367"></A> directive automatically import
<A NAME="@default368"></A>
<A NAME="@default369"></A>
the module <TT>eclipse_language</TT>, which provides the standard set
of ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> built-in predicates. 
To create a module that uses a different language dialect, use
<A HREF="../bips/kernel/modules/module-3.html"><B>module/3</B></A><A NAME="@default370"></A>.
For instance
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
:- module(mystdcode, [], iso).
</PRE></BLOCKQUOTE>
creates a module in which you can use ISO Standard Prolog<SUP><A NAME="text7" HREF="umsroot037.html#note7">4</A></SUP>,
but not all of ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>'s usual language features.
Note that the third argument (here <TT>iso</TT>) simply
specifies a library which implements the desired language,
so new languages can be added easily.<BR>
<BR>
<A NAME="toc66"></A>
<H3 CLASS="subsection"><A NAME="htoc106">7.4.2</A>&nbsp;&nbsp;Creating and Erasing Modules at Runtime</H3>

A module can also be created explicitly by a running program with
<A HREF="../bips/kernel/modules/create_module-1.html"><B>create_module/1</B></A><A NAME="@default371"></A> or
<A HREF="../bips/kernel/modules/create_module-3.html"><B>create_module/3</B></A><A NAME="@default372"></A>
and erased with
<A HREF="../bips/kernel/modules/erase_module-1.html"><B>erase_module/1</B></A><A NAME="@default373"></A>. 
The latter should be used with care, erasing a module while a
predicate defined in that module is being executed can provoke
unpredictable results. The same holds for trying to erase essential
system modules.
<BR>
<BR>
<A NAME="toc67"></A>
<H3 CLASS="subsection"><A NAME="htoc107">7.4.3</A>&nbsp;&nbsp;Initialization and Finalization</H3>
<A NAME="initfini"></A>
<A NAME="@default374"></A>
<A NAME="@default375"></A>
Sometimes modules have global state which needs to be initialised
or finalised. For this purpose, modules can have
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>Local Initialization Goals:</B><DD CLASS="dd-description">
these are specified as
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
:- local initialization(Goal).
</PRE></BLOCKQUOTE>
and are executed just after the module containing them has been loaded.
<DT CLASS="dt-description"><B>Exported Initialization Goals:</B><DD CLASS="dd-description">
these are specified as
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
:- export initialization(Goal).
</PRE></BLOCKQUOTE>
and are executed whenever the module containing the declaration gets
imported into another module. The call will happen in the context of
the importing module.
<DT CLASS="dt-description"><B>Finalization Goals:</B><DD CLASS="dd-description">
these are specified as
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
:- local finalization(Goal).
</PRE></BLOCKQUOTE>
and are executed just before the module containing them gets erased.
Modules can get erased either explicitly through
<A HREF="../bips/kernel/modules/erase_module-1.html"><B>erase_module/1</B></A><A NAME="@default376"></A> 
or implicitly when the module is re-compiled, or when the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP>
session is exited. Finalization goals should not do any I/O because
in the case of an embedded ECLiPSe, I/O may no longer be available at
finalization time.</DL>
<A NAME="toc68"></A>
<H3 CLASS="subsection"><A NAME="htoc108">7.4.4</A>&nbsp;&nbsp;Locking Modules</H3>
<A NAME="locking"></A>
<A NAME="@default377"></A>
By default, ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> does not strictly enforce the hiding of
module internals. This facilitates program development as is makes
it possible to inspect and trace without being too concerned about module
boundaries. E.g. you can set a spy point on a local predicate p/3
in module othermod by calling:
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
:- spy(p/3)@othermod.
</PRE></BLOCKQUOTE>
Once a module implementation is stable and there is a need for privacy,
it is possible to <EM>lock</EM> a module. Locking makes it impossible
to access internal, local items from outside the module. Of course,
the module can still be used though its interface.
The built-in predicates related to locking are
<A HREF="../bips/kernel/modules/lock-0.html"><B>lock/0</B></A><A NAME="@default378"></A> which provides
a definitive lock,
<A HREF="../bips/kernel/modules/lock_pass-1.html"><B>lock_pass/1</B></A><A NAME="@default379"></A>
which allows subsequent unlocking using a password (
<A HREF="../bips/kernel/modules/unlock-2.html"><B>unlock/2</B></A><A NAME="@default380"></A>),
and
<A HREF="../bips/kernel/modules/get_module_info-3.html"><B>get_module_info/3</B></A><A NAME="@default381"></A>
which allows to check whether a module is locked.
<A HREF="../bips/kernel/modules/lock-0.html"><B>lock/0</B></A><A NAME="@default382"></A> and
<A HREF="../bips/kernel/modules/lock_pass-1.html"><B>lock_pass/1</B></A><A NAME="@default383"></A> are
usually used as a directive in the source file of the module to be locked.<BR>
<BR>
<HR>
<A HREF="umsroot040.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="umsroot037.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
</BODY>
</HTML>
